library(ggplot2)
Warning: package 'ggplot2' was built under R version 4.3.3
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(tidyr)
library(lubridate)

Attaching package: 'lubridate'
The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(stringr)
library(emojifont)
Warning: package 'emojifont' was built under R version 4.3.3
library(ggtext)
Warning: package 'ggtext' was built under R version 4.3.3
library(leaflet)
library(sf)
Linking to GEOS 3.11.2, GDAL 3.7.2, PROJ 9.3.0; sf_use_s2() is TRUE
library(readr)
library(jsonlite)
airbnb_data <- read_csv("airbnb_data.csv")
Rows: 225 Columns: 50
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (16): Name, Title, Listing URL, Price, Qualifier, Can Instant Book, Orig...
dbl (10): Id, Beds, Baths, Bedrooms, Average Rating, Number of Reviews, Clea...
lgl (24): City, Cleaning Fee, Airbnb Service Fee, Total Charged for Stay, Ea...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
rats <- read_csv("Rat_Sightings_20240507.csv")|>
  filter(Latitude!="NA",
         Longitude!="NA")
Rows: 241846 Columns: 38
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (26): Created Date, Closed Date, Agency, Agency Name, Complaint Type, De...
dbl  (5): Unique Key, X Coordinate (State Plane), Y Coordinate (State Plane)...
lgl  (7): Vehicle Type, Taxi Company Borough, Taxi Pick Up Location, Bridge ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
parks <- read_csv("Parks_Properties_20240507.csv")
Rows: 2047 Columns: 35
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr  (20): ADDRESS, BOROUGH, CLASS, DEPARTMENT, EAPPLY, GISPROPNUM, GlobalID...
dbl  (10): ACRES, COMMUNITYBOARD, COUNCILDISTRICT, GISOBJID, NYS_ASSEMBLY, N...
lgl   (4): PERMIT, PIP_RATABLE, RETIRED, WATERFRONT
dttm  (1): ACQUISITIONDATE

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
parks_sf <- st_as_sf(parks, wkt = "multipolygon")



url<- "https://data.cityofnewyork.us/resource/fi97-k4k6.json"

farmers_markets <- fromJSON(url)|>
  mutate(latitude=as.numeric(latitude),
         longitude=as.numeric(longitude))
rats_location <- rats |>
  select(Latitude, Longitude) 

rats_location
# A tibble: 239,532 × 2
   Latitude Longitude
      <dbl>     <dbl>
 1     40.7     -73.9
 2     40.8     -73.9
 3     40.8     -73.9
 4     40.8     -74.0
 5     40.7     -74.0
 6     40.8     -73.9
 7     40.7     -74.0
 8     40.6     -74.0
 9     40.8     -74.0
10     40.7     -74.0
# ℹ 239,522 more rows
rats_graph<-rats_location|>
  sample_n(225)  
airbnb_location<-airbnb_data|>
  select(Latitude, Longitude)
house_icon <- makeIcon(
  iconUrl = "https://www.iconeasy.com/icon/png/System/Vista%20General/house.png",
  iconWidth = 29,
  iconHeight = 29
)

rat_icon <- makeIcon(
  iconUrl = "https://icons.iconarchive.com/icons/google/noto-emoji-animals-nature/256/22251-rat-icon.png",
  iconWidth = 28,
  iconHeight = 28
)

leaflet() |>
  addTiles() |>
  setView(lng = -74.00, lat = 40.71, zoom = 12) |>
  addMarkers(data = airbnb_data, lng = ~Longitude, lat = ~Latitude, icon = house_icon,
     popup = ~paste("<a href='", `Listing URL`, "'><b>", Title, "</b></a>", "</br>", Name, "</br>", Price, Qualifier))|>
  addMarkers(data=rats_graph, lng=~Longitude, lat=~Latitude, icon = rat_icon, popup = ~paste("squeak squeak:)"))
carrot_icon <- makeIcon(
  iconUrl = "https://images.emojiterra.com/google/noto-emoji/unicode-15.1/color/svg/1f955.svg",
  iconWidth = 29,
  iconHeight = 29
)

leaflet() |>
  addTiles() |>
  setView(lng = -74.00, lat = 40.71, zoom = 12)|>
  addMarkers(data=farmers_markets, lng=~longitude, lat=~latitude, icon = carrot_icon, popup = ~paste(marketname, "</br>", daysoperation, hoursoperations))
leaflet() |>
  addTiles() |>
  setView(lng = -74.00, lat = 40.71, zoom = 12)|>
  addPolygons(data=parks_sf, color="deeppink", popup = ~paste(SIGNNAME))